# Your NumArray object will be instantiated and called as such:
# obj = NumArray(nums)
# param_1 = obj.sumRange(i,j)


class NumArray:
    """这样多加个0进去确实比每次判断省时间"""
    def __init__(self, nums: list):
        self.nums = [0] + nums
        for i in range(1, len(self.nums)):
            self.nums[i] = self.nums[i-1] + self.nums[i]

    def sumRange(self, i: int, j: int) -> int:
        return self.nums[j+1] - self.nums[i]


class NumArray2:
    def __init__(self, nums: list):
        self.nums = nums
        for i in range(1, len(nums)):
            self.nums[i] = self.nums[i-1] + self.nums[i]

    def sumRange(self, i: int, j: int) -> int:
        return self.nums[j] - (self.nums[i-1] if i > 0 else 0)


a = NumArray([-2, 0, 3, -5, 2, -1])
print(a.sumRange(0, 2))
print(a.sumRange(2, 5))
print(a.sumRange(0, 5))
